﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using NPOI.HSSF.UserModel;
using Test;

namespace WebScrapper {
    class Program {
        static void Main(string[] args) {
            AuYellowPage site = new AuYellowPage();
            List<Company> companies = site.Search("Acupuncture", 0);
            Thread.Sleep(TimeSpan.FromSeconds(30));
            var page2 = site.Search("Acupuncture", 1);
            companies.AddRange(page2);
            var workbook = new HSSFWorkbook();
            var sheet = workbook.CreateSheet("Acupuncture");
            var headerRow = sheet.CreateRow(0);
            headerRow.CreateCell(0).SetCellValue("Categories");
            headerRow.CreateCell(1).SetCellValue("Business name");
            headerRow.CreateCell(2).SetCellValue("Address");
            headerRow.CreateCell(3).SetCellValue("City");
            headerRow.CreateCell(4).SetCellValue("State");
            headerRow.CreateCell(5).SetCellValue("PostCode");
            headerRow.CreateCell(5).SetCellValue("Phone");
            headerRow.CreateCell(5).SetCellValue("Email");
            headerRow.CreateCell(5).SetCellValue("Website");
            for (int i = 0; i < companies.Count; i++) {
                var company = companies[i];
                sheet.CreateRow(i + 1);
                headerRow.CreateCell(0).SetCellValue(company.Category);
                headerRow.CreateCell(1).SetCellValue(company.BussinessName);
                headerRow.CreateCell(2).SetCellValue(company.StreetAddress);
                headerRow.CreateCell(3).SetCellValue(company.City);
                headerRow.CreateCell(4).SetCellValue(company.State);
                headerRow.CreateCell(5).SetCellValue(company.PostCode);
                headerRow.CreateCell(5).SetCellValue(company.Phone1);
                headerRow.CreateCell(5).SetCellValue(company.Email);
                headerRow.CreateCell(5).SetCellValue(company.Website);
            }
            using (var file =new FileStream("ouput.xls",FileMode.Create)) {
                workbook.Write(file);
                file.Flush();
                file.Close();
            }
        }
    }
}
